﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using HotelSoftBusLib;

namespace HotelSoftBusWeb
{
    public static class Util
    {
        private static readonly string CLIENT_DEVICE_FILE = "ClientDevice.xml";

        /// <summary>
        /// 读取设备客户端的信息
        /// </summary>
        public static void LoadClientDevices()
        {

            lock (WebApp.mClientDevice_Sync)
            {
                WebApp.ClientDevices.Clear();

                string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

                XElement root = XElement.Load(path+"\\"+CLIENT_DEVICE_FILE);

                IEnumerable<XElement> els = root.Elements();

                foreach (var e in els)
                {
                    ClientDevice cd = new ClientDevice();

                    int t=int.Parse(e.Attribute("DeviceType").Value);

                    cd.ClientDeviceType = (ClientDeviceTypeEnum)t;
                    cd.House = e.Attribute("House").Value;
                    cd.IpAddress = e.Attribute("IpAddress").Value;
                    cd.Port = e.Attribute("Port").Value;

                    WebApp.ClientDevices.Add(cd);
                }

                
            }
            
        }

    }
}